package com.m1.tzolkin.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import com.m1.tzolkin.model.board.ITZBoard;
import com.m1.tzolkin.model.exceptions.NoAvailableSkullException;
import com.m1.tzolkin.model.exceptions.NotAvailableActionException;
import com.m1.tzolkin.model.exceptions.NotEnoughCornException;
import com.m1.tzolkin.model.players.ITZPlayer;

/**
 * Une action jouable sur une case.
 * Une action donne des ressources au joueur qui l'appelle, ou modifie ses permissions
 *  pour lui permettre d'effectuer diff�rentes choses.
 */
public abstract class Action implements IAction {
	
	// ATTRIBUTS
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 7853766177746565855L;
	private boolean available = true;
	private final ActionType type;
	protected final PropertyChangeSupport listeners;
	
	public Action() {
		type = null;
		listeners = new PropertyChangeSupport(this);
	}
	
	public Action(ActionType t) {
		type = t;
		listeners = new PropertyChangeSupport(this);
	}
	
	// REQUETES
	
	@Override
	public boolean isAvailable() {
		return available;
	}
	
	@Override
	public ActionType getType() {
		return type;
	}
	
	@Override
	public PropertyChangeListener[] getPropertyChangeListeners() {
		return listeners.getPropertyChangeListeners();
	}

	// COMMANDES
	
	@Override
	public abstract void doAction(ITZBoard b, ITZPlayer p) throws NotAvailableActionException, NoAvailableSkullException, NotEnoughCornException;
	
	@Override
	public void addPropertyChangeListener(PropertyChangeListener l) {
		listeners.addPropertyChangeListener(l);
	}
	
	@Override
	public void removePropertyChangeListener(PropertyChangeListener l) {
		listeners.removePropertyChangeListener(l);
	}
	
	protected void setAvailable(boolean av) {
		available = av;
	}
	
}
